package netty5.serializable.messagepack;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;
import org.msgpack.MessagePack;

import java.util.Objects;

/**
 * Created by GanJc on 2015/11/21.
 */
public class MessagePackEncoder extends MessageToByteEncoder<Objects> {

    public MessagePackEncoder() {
        System.out.println("构造encoder");
    }

    @Override
    protected void encode(ChannelHandlerContext ctx, Objects objects, ByteBuf byteBuf) throws Exception {
        System.out.println("处理encoder:"+ objects);
        MessagePack pack = new MessagePack();
        //序列化
        byte[] raw = pack.write(objects);
        byteBuf.writeBytes(raw);
    }
}
